//渲染省钱控商品点击后的详情页面(此处是content的内容)
function bindHtml(arr) {
    let html = ""
    arr.forEach(item => {
        html += ` 
        <div class="info">
        <div class="title">
            <h4>${item.productName}</h4>
        </div>
        <div class="other">
            <span>${item.productFrom} | ${item.productTime}</span>
            <span>${item.productTips}</span>
        </div>
        <div class="word">
            <p>
                ${item.productImg2}
                ${item.productInfo}
                ${item.productInfo1}  
                ${item.productInfo2}         
            </p>
        </div>
        <div class="image">
           ${item.productImgSm}
        </div>
        <div class="city">${item.productCity}</div>
    </div>`
    })
    return html
}
//此处是评论的内容
function bindHtml2(arr) {
    let comments = ""
    arr.forEach(item => {
        comments += `
        ${item.productComment}
    `
    })
    return comments;
}


//接收正确的接口，在浏览器后拼接参数
var url = window.location.href
function parseQuery(url) {
    var queryObj = {};
    var reg = /[?&]([^=&#]+)=([^&#]*)/g;
    var querys = url.match(reg);
    if (querys) {
        for (var i in querys) {
            var query = querys[i].split('=');
            var key = query[0].substr(1),
                value = query[1];
            queryObj[key] ? queryObj[key] = [].concat(queryObj[key], value) : queryObj[key] = value;
        }
    }
    return queryObj;
}
let str = parseQuery(url).productid
console.log(str);


//请求省钱控商品详情数据
ajax({
    url: 'http://chst.vip:1234/api/getmoneyctrlproduct?productid=' + str
}).then(res => {
    console.log(res.result);
    let html = bindHtml(res.result)
    let comments = bindHtml2(res.result)
    content.innerHTML = html
    comment.innerHTML = comments
})




